﻿#region Using namespaces

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

#endregion

namespace BOL.Apps.GeneNetworkBrowser.Converters
{
    public class PropertyColorConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var minColor = System.Drawing.Color.FromName(values[0].ToString());
            var minH = (double)minColor.GetHue();
            var maxColor = System.Drawing.Color.FromName(values[1].ToString());
            var maxH = (double)minColor.GetHue();

            double min = Double.Parse(values[2].ToString());
            double max = Double.Parse(values[3].ToString());
            var value = Double.Parse(values[4].ToString()) / (max - min);

            double h = (value < 0.5) ? minH : maxH;
            double s = (value < 0.5) ? (0.5 - value) * 2 : (value - 0.5) * 2;
            double l = 0.5;

            return new SolidColorBrush(ColorSystems.FromHSL(h, s, l));
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    } 
}
